package com.gs.synedocket.presenter;

import com.google.gson.reflect.TypeToken;
import com.gs.synedocket.apiresult.ApiResultData;
import com.gs.synedocket.db.dto.DriverSignDto;
import com.gs.synedocket.model.DocketModel;
import com.gs.synedocket.model.listener.OnResultListener;
import com.gs.synedocket.view.IDriverView;

import java.lang.reflect.Type;

public class DriverPresenter extends BasePresenter<IDriverView> {
    private DocketModel docketModel = new DocketModel();

    public void update(DriverSignDto bean) {
        if (getView() != null) {
            getView().showLoading();
            Type typeofT=new TypeToken<ApiResultData<String>>(){}.getType();
            docketModel.update(bean, new OnResultListener() {
                @Override
                public void onSuccess(Object aipResult) {
                    if (getView() != null) {
                        getView().hideLoading();
                        getView().onUpdateSuccess((ApiResultData<String>)aipResult);
                    }
                }

                @Override
                public void onFails(Exception e) {
                    if (getView() != null) {
                        getView().hideLoading();
                        getView().onUpdateFails(e);
                    }
                }
            },typeofT);
        }
    }
}
